<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::Observing::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::Observing::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/activerecord/lib/active_record/observer_rb.html">
                vendor/rails/activerecord/lib/active_record/observer.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001119">inherited</a>&nbsp;&nbsp;
      <a href="#M001118">instantiate_observers</a>&nbsp;&nbsp;
      <a href="#M001117">observers</a>&nbsp;&nbsp;
      <a href="#M001116">observers=</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001118" class="method-detail">
        <a name="M001118"></a>

        <div class="method-heading">
          <a href="#M001118" class="method-signature">
          <span class="method-name">instantiate_observers</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Instantiate the global ActiveRecord <a
href="ClassMethods.html#M001117">observers</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001118-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001118-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/observer.rb, line 34</span>
34:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instantiate_observers</span>
35:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@observers</span>.<span class="ruby-identifier">blank?</span>
36:         <span class="ruby-ivar">@observers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">observer</span><span class="ruby-operator">|</span>
37:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">observer</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_sym</span>) <span class="ruby-comment cmt"># Symbol or String</span>
38:             <span class="ruby-identifier">observer</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">camelize</span>.<span class="ruby-identifier">constantize</span>.<span class="ruby-identifier">instance</span>
39:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">observer</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:instance</span>)
40:             <span class="ruby-identifier">observer</span>.<span class="ruby-identifier">instance</span>
41:           <span class="ruby-keyword kw">else</span>
42:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;#{observer} must be a lowercase, underscored class name (or an instance of the class itself) responding to the instance method. Example: Person.observers = :big_brother # calls BigBrother.instance&quot;</span>
43:           <span class="ruby-keyword kw">end</span>
44:         <span class="ruby-keyword kw">end</span>
45:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001117" class="method-detail">
        <a name="M001117"></a>

        <div class="method-heading">
          <a href="#M001117" class="method-signature">
          <span class="method-name">observers</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Gets the current <a href="ClassMethods.html#M001117">observers</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001117-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001117-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/observer.rb, line 29</span>
29:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">observers</span>
30:         <span class="ruby-ivar">@observers</span> <span class="ruby-operator">||=</span> []
31:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001116" class="method-detail">
        <a name="M001116"></a>

        <div class="method-heading">
          <a href="#M001116" class="method-signature">
          <span class="method-name">observers=</span><span class="method-args">(*observers)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Activates the <a href="ClassMethods.html#M001117">observers</a> assigned.
Examples:
</p>
<pre>
  # Calls PersonObserver.instance
  ActiveRecord::Base.observers = :person_observer

  # Calls Cacher.instance and GarbageCollector.instance
  ActiveRecord::Base.observers = :cacher, :garbage_collector

  # Same as above, just using explicit class references
  ActiveRecord::Base.observers = Cacher, GarbageCollector
</pre>
<p>
Note: Setting this does not instantiate the <a
href="ClassMethods.html#M001117">observers</a> yet. <a
href="ClassMethods.html#M001118">instantiate_observers</a> is called during
startup, and before each development request.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001116-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001116-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/observer.rb, line 24</span>
24:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">observers=</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">observers</span>)
25:         <span class="ruby-ivar">@observers</span> = <span class="ruby-identifier">observers</span>.<span class="ruby-identifier">flatten</span>
26:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M001119" class="method-detail">
        <a name="M001119"></a>

        <div class="method-heading">
          <a href="#M001119" class="method-signature">
          <span class="method-name">inherited</span><span class="method-args">(subclass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Notify <a href="ClassMethods.html#M001117">observers</a> when the observed
class is subclassed.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001119-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001119-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/observer.rb, line 49</span>
49:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inherited</span>(<span class="ruby-identifier">subclass</span>)
50:           <span class="ruby-keyword kw">super</span>
51:           <span class="ruby-identifier">changed</span>
52:           <span class="ruby-identifier">notify_observers</span> <span class="ruby-identifier">:observed_class_inherited</span>, <span class="ruby-identifier">subclass</span>
53:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>